package day13.Ti.synchronizedDome;

public class Ti01 {
    public static void main(String[] args) {
        MyRunnable mr = new MyRunnable();
        Thread t1 = new Thread(mr,"窗口一");
        Thread t2 = new Thread(mr,"窗口二");
        Thread t3 = new Thread(mr,"窗口三");
        t1.start();
        t2.start();
        t3.start();
    }
}

class MyRunnable implements Runnable {
    private int ticket = 100;
    private Object obj = new Object();

    @Override
    public void run() {
        while (true) {
            synchronized (obj) {
                if (ticket <= 0) {
                    System.out.println("卖完了");
                    break;
                } else {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {


                    }
                    ticket--;
                    System.out.println(Thread.currentThread().getName() + "在卖票,剩余" + ticket);
                }
            }
        }
    }
}
